#!/usr/bin/perl

package Card;

my $name;
my $value;

sub new {

	my $class = shift;
	my $self;
	if (@_ == 2) {
		$self = {
			_name => $_[0],
			_value => $_[1],
		};
	} elsif (@_ == 1) {
		if ($_[0] =~ /^[+-]?\d+$/) {
			$self = {
				_value => $_[0],
			};
		} else {
			$self = {
				_name => $_[0],
			};		}
	} elsif (@_ == 0) {
		$self = {
			_name => "",
			_value => -1,
		};
	}
	bless $self, $class;
	return $self;
}

sub getname {
	my ($self) = @_;
	$self->{_name};
}

sub getvalue {
	my ($self) = @_;
	$self->{_value};
}

sub setname {
	my ($self, $name) = @_;
	$self->{_name} = $name if defined($name);
	$self->{_name};
	
	my $value = substr $name, 1;
	if ($value eq "A") {
		$self->{_value} = 1;
	} elsif ($value eq "J") {		
		$self->{_value} = 11;
	} elsif ($value eq "Q") {
		$self->{_value} = 12;
	} elsif ($value eq "K") {
		$self->{_value} = 13;
	} else {
		$self->{_value} = $value;
	}
}

sub setvalue {
	my ($self, $value) = @_;
	$self->{_value} = $value if defined($value);
	$self->{_value};
}

sub getSuit {
	my ($self) = @_;
	$suit = substr $self->{_name}, 0, 1;
	$suit;
}

sub getColor {
	my ($self) = @_;
	$suit = substr $self->{_name}, 0, 1;
	if ($suit eq "H" || $suit eq "D") {
		return "R";
	} elsif ($suit eq "C" || $suit eq "S") {
		return "B";
	}
}
1;